package com.itsc.action;

import java.util.List;

import com.itsc.entities.Order;
import com.itsc.service.inter.IOrderService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ModelDriven;

public class OrderAction implements ModelDriven<Order>{

	private Order model = new Order();
	private IOrderService orderService;
	
	private List<Integer> check_id;
	
	public List<Integer> getCheck_id() {
		return check_id;
	}
	public void setCheck_id(List<Integer> check_id) {
		this.check_id = check_id;
	}
	public void setOrderService(IOrderService orderService) {
		this.orderService = orderService;
	}
	@Override
	public Order getModel() {
		// TODO Auto-generated method stub
		return model;
	}
	
	public String list() throws Exception{
		List<Order> orderList = orderService.selectAll();
		ActionContext.getContext().put("orderList", orderList);
		
		return "list";
	}
	
	public String show() throws Exception{
		
		Order order = orderService.selectById(model.getOrder_id());
		ActionContext.getContext().getValueStack().push(order);
		
		return "show";
	}
	
	public String delete() throws Exception{
		Order order = orderService.selectById(model.getOrder_id());
		orderService.delete(order);
		return "ok";
	}
	
	public String moredelete() throws Exception{
		for(Integer id : check_id){
			Order order = orderService.selectById(id);
			orderService.delete(order);
		}
		
		return "ok";
	}
	

}
